/** 提示 alert、toast、confirm ... */

//关闭toast
function closeToast() {
	//uexWindow.destroyProgressDialog();
	//return;
	uexWindow.closeToast();
}

// 重写alert
window.alert = function(msg, callback) {
	appcan.window.alert({
		title: '提示',
		buttons: ['确定'],
		content: msg,
		callback: callback
	});
}

function confirm2(cb, message, title, buttonLable) {
	//confirm确认选择
	if(typeof cb !== 'function') {
		alert('缺少回调函数');
		return;
	}
	if(typeof uexWindow === 'undefined') {
		var r = confirm(message);
		if(cb) {
			cb(r);
		}
		return;
	}
	if(!message) {
		var message = '确认执行此操作？'
	}
	if(!title) {
		var title = '提示';
	}
	if(!buttonLable) {
		var buttonLable = ['确定', '取消'];
	}
	uexWindow.cbConfirm = function(opId, dataType, data) {
		console.log('您选择了第 %s 项', data);
		cb(data);
	}
	uexWindow.confirm(title, message, buttonLable);
}

//toast提示
function toast(msg, duration, location, type) {
	var locationObj = {
		"leftTop": 1,
		"top": 2,
		"rightTop": 3,
		"left": 4,
		"middle": 5,
		"right": 6,
		"bottomLeft": 7,
		"bottom": 8,
		"bottomRight": 9
	}
	if(!msg) {
		msg = '提示';
	}
	if(!duration) {
		duration = 3000;
	}
	if(!location) {
		location = 5; //默认居中显示
	}
	if(locationObj[location]) {
		location = locationObj[location];
	}
	if(!type) {
		type = 0;
	}
	if(typeof type !== 'number' && duration === 0) {
		type = 1;
	} else {
		type = 0;
	}
	uexWindow.toast(type, location, msg, duration);
}

/* 打开带输入框的弹框 */
function openPopBox() {
	var _pop = $('#PopupBox_5'),
		_chat = $('.chat');
	if(_pop.hasClass('uhide') || _chat.hasClass('uhide')) {
		_pop.removeClass('uhide');
		_chat.removeClass('uhide');
	}

	appcan.button(_chat, "", function(e) {
		e.stopPropagation();
		if(!$(this).hasClass('uhide'))
			closePopBox();
	});

	appcan.button(".pop_cancelBtn", "btn-act", function(e) {
		closePopBox();
	});
}

function actionSheet(cb, buttonLables, cancel, title) {
    if (typeof cb !== 'function') {
        alert('缺少回调函数');
        return;
    }
    if (!cancel) {
        cancel = '取消'
    }
    if (!title) {
        title = '';
    }
    if (!buttonLables) {
        buttonLables = ['演示选项一', '演示选项二', '演示选项三']
    }
    uexWindow.cbActionSheet = function(opId, dataType, data) {
        console.log('您选择了第 %s 项', data);
        cb(data);
    }
    uexWindow.actionSheet(title, cancel, buttonLables);
}
/* 关闭带输入框的弹框 */
function closePopBox() {
	var _pop = $('#PopupBox_5'),
		_chat = $('.chat');
	_pop.addClass('uhide');
	_chat.addClass('uhide');
}